import React from 'react';
import { render } from 'react-dom';
import App from './component/App';

import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import counterReducer from './component/reducer';
import { increaseAction, decreaseAction, increaseIfOddAction, increaseDelayAction } from './component/action';

render(<App />, document.querySelector('#root'));

// 1. 创建 store
let store = createStore(counterReducer, applyMiddleware(thunk));

console.log('初始 state 状态: ', store.getState());

// 2. 设置监听, state 更新完成后, 监听回调函数执行.
let unsubscribe = store.subscribe(() => {
    console.log('更新 state 完成, 现在状态: ', store.getState());
});

// 3. dispatch
store.dispatch(increaseAction());
store.dispatch(increaseIfOddAction());
store.dispatch(increaseDelayAction());
console.log(4);
store.dispatch(decreaseAction());

// 4. 停止监听
// unsubscribe();
			